package com.yulongtian.oneProblemEveryDay.month202211.day20221106;

/**
 * https://leetcode.cn/problems/goal-parser-interpretation/
 * 可
 *
 * @author yulongTian
 * @create 2022-11-06 8:52
 */
public class Test01 {
    public static void main(String[] args) {
        System.out.println(interpret("(al)G(al)()()G"));
    }

    public static String interpret(String command) {
        if (command.length() == 1) {
            return command;
        }
        StringBuffer res = new StringBuffer();
        for (int i = 0; i < command.length(); i++) {
            if (command.charAt(i) == 'G') {
                res.append(command.charAt(i));
            }

            if (command.charAt(i) == '(') {
                if (i + 1 < command.length() && command.charAt(i + 1) == ')') {
                    res.append('o');
                    i++;
                    continue;
                }
                if (i + 1 < command.length() && command.charAt(i + 1) == 'a') {
                    res.append('a').append('l');
                    i += 3;
                    continue;
                }

            }

        }

        return res.toString();
    }

}
